package tv.acgn.advertisement.publish.action;

import java.util.List;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import tv.acgn.advertisement.publish.exception.AbstractAdPubException;
import tv.acgn.advertisement.publish.po.AdPlanPO;
import tv.acgn.advertisement.publish.service.AdPlanService;
import tv.acgn.advertisement.publish.vo.adplan.AdPlanRequestVO;
import tv.acgn.advertisement.publish.vo.adplan.AdPlanResponseVO;

/**
 * @author : junG
 * @program : advertisement-ad-pub-action
 * @description : 推广计划 分发器
 * @date : 2019-06-02 02:17
 **/

@RestController
@Slf4j
public class AdPlanAction {

    @Autowired
    private AdPlanService adPlanService;

    @GetMapping(value = "/plan/{id}")
    public AdPlanPO getAdPlan(@PathVariable(value = "id") String planId) throws AbstractAdPubException {
        return adPlanService.getAdPlan(planId);
    }

    @GetMapping(value = "/plan")
    public List<AdPlanPO> getAdPlanBatch(@RequestBody List<AdPlanRequestVO> adPlanRequestVOList)
        throws AbstractAdPubException {
        List<String> adPlanList = adPlanRequestVOList.stream().map(x -> x.getPlanId()).collect(Collectors.toList());
        return adPlanService.getAdPlanBatch(adPlanList);
    }

    @GetMapping(value = "/plan/find")
    public List<AdPlanPO> findUser(@RequestBody AdPlanRequestVO requestVO) throws AbstractAdPubException {
        return adPlanService.findAdPlan(requestVO);
    }

    @PostMapping(value = "/plan")
    public AdPlanResponseVO addPlan(@RequestBody AdPlanRequestVO requestVO) throws AbstractAdPubException {
        return adPlanService.addAdPlan(requestVO);
    }

    @PutMapping(value = "/plan")
    public AdPlanResponseVO updatePlan(@RequestBody AdPlanRequestVO requestVO) throws AbstractAdPubException {
        return adPlanService.updateAdPlan(requestVO);
    }

    @DeleteMapping(value = "/plan/{id}")
    public AdPlanResponseVO deletePlan(@PathVariable(value = "id") String planId) throws AbstractAdPubException {
        return adPlanService.deleteAdPlan(planId);
    }

}
